﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using LibraryO2S;
using BusinessObjects.BO_GetObjects;


public partial class Controls_SettingNew : System.Web.UI.UserControl
{
    private DataTable objDT;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            loadSDdlGroup();
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        Response.Redirect(Request.Url.ToString());
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        DataTable admin = (DataTable)Session["Admin"];
        string result = BO_Settings.Insert(Convert.ToInt32(ddlGroup.SelectedValue), txtKey.Text.Trim(), txtName.Text.Trim(), txtDescription.Text.Trim(), txtValue.Text.Trim(), Convert.ToInt32(ddlType.SelectedValue), txtTypeValue.Text.Trim(), Convert.ToInt32(txtSortDisplay.Text), DateTime.Now, admin.Rows[0]["USER_NAME"].ToString(), DateTime.Now, "", true);
        if (result.Equals("0"))
            divMessage.InnerHtml = O2S_Message.Error("Lỗi", "Chưa thực hiện được.");
        else
            divMessage.InnerHtml = O2S_Message.Success("Thông Báo", "Thực hiện thành công.");
    }
    private void loadSDdlGroup()
    {
        objDT = BO_SettingGroups.SelectAll(1);
        ddlGroup.DataSource = objDT;
        ddlGroup.DataTextField = "FULL_SETTING_NAME";
        ddlGroup.DataValueField = "SETTING_GROUP_ID";
        ddlGroup.DataBind();
    }
}